package simulator;
import storage.Block;
/**
* The client is responsible to accept a block read request from the user.
* Once the request is accepted, the block is served either from the local cache,
* the global cache or the server disk.
*
* @author Nodirjon Siddikov
*/
public class Client
{
private int _id; //ID of the client (could be anything that identifies the client such as IP address)
protected int _maxNoOfCacheBlocks; //max number of local cache lines
protected int _gblCacheSize; //global cache size (in Bytes)
protected int _lclCacheSize; //local cache size (in Bytes)
protected static final float _hashTableLoadFactor = 0.75f; //about 75% of the hash table will be full
protected Manager _manager;
//statistical variables
protected int _ttlNoOfReadRequests; //per each client (running total)
protected double _blckAccessTime; //per read request, reset to 0 every time new request is submitted
protected double _ttlBlockAccessTime; //per each client (running total)
protected int _lclCacheHitCount, _rmtCacheHitCount, _serverDiskHitCount;
protected int _lclCacheMissCount, _rmtCacheMissCount;
//variables to keep track of communication only with manager (but not clients)
protected int _lookUpCount, _replacementCount, _consistencyCount; //running totals
//communication overhead calculation (among manager and clients)
protected int
//used in N-Chance algorithm for rmtBlock exchange with manager, running total
_digestExchangeCount,
//used in all algorithms when reading a block from rmtClient's cache memory, running total
_blockReadCount,
//used in Hint algorithm to exchange hints and facts, running total
_hintExchangeCount,
//used in all algorithms when block is relocated between client computers, running total
_relocationCount;
//constructor
public Client(int id)
{
_id = id;
}
//get the client ID
public int getID()
{
return _id;
}
//assign the manager
public void setManager(Manager m)
{
return;
}
public Block receiveReadRequest(int diskBlockID)
{
return null;
}
//statistics
public double getLocalCacheHitRate() //in percentage
{
return (double)_lclCacheHitCount / _ttlNoOfReadRequests;
}
public double getLocalCacheMissRate() //in percentage
{
return (double)_lclCacheMissCount / _ttlNoOfReadRequests;
}
public double getRemoteCacheHitRate() //in percentage
{
return (double)_rmtCacheHitCount / _ttlNoOfReadRequests;
}
public double getRemoteCacheMissRate() //in percentage
{
return (double)_rmtCacheMissCount / _ttlNoOfReadRequests;
}
public double getServerDiskHitRate() //in percentage
{
return (double)_serverDiskHitCount / _ttlNoOfReadRequests;
}
public double getAvgBlockAccessTime() //per read request
{
return _ttlBlockAccessTime / _ttlNoOfReadRequests;
}
public double getLocalCacheHitFraction()
{
return getAvgBlockAccessTime() * getLocalCacheHitRate();
}
public double getRemoteCacheHitFraction()
{
return getAvgBlockAccessTime() * getRemoteCacheHitRate();
}
public double getServerDiskHitFraction()
{
return getAvgBlockAccessTime() * getServerDiskHitRate();
}
//variables needed to keep track of manager load
public double getLookUpFraction()
{
return (double)_lookUpCount / _ttlNoOfReadRequests;
}
public double getReplacementFraction()
{
return (double)_replacementCount / _ttlNoOfReadRequests;
}
public double getConsistencyFraction()
{
return (double)_consistencyCount / _ttlNoOfReadRequests;
}
//used for calculation of communication overhead for client (in and out of Bytes)
public double getDigestExchangeFraction()
{
return 0;
}
public double getBlockReadFraction()
{
return 0;
}
public double getRelocationFraction()
{
return 0;
}
public double getHintExchangeFraction()
{
return 0;
}
public double getCommunicationOverhead()
{
return getDigestExchangeFraction()+ getBlockReadFraction() + getHintExchangeFraction();
}
}